﻿@page
@model FytSoa.Web.Pages.FytAdmin.Cms.ArticleModifyModel
@{
    ViewData["Title"] = "文章管理";
    Layout = AdminLayout.Pjax(HttpContext);
}
<div id="container">
    <form class="layui-form form-cus form-back" action="">
        <div class="panel-body">
            <div class="panel-addpic">
                <div class="text">基本属性</div>
                <div class="form-cur-wall">
                    <label>所属栏目：</label>
                    <div class="layui-input-block">
                        <select name="ParentId" lay-verify="required" lay-search="">
                            <option value="0">父级</option>
                            @{
                                if (Model.ColumnList.Any())
                                {
                                    foreach (var item in Model.ColumnList)
                                    {
                                        if (item.Id == Model.Article.ColumnId)
                                        {
                                            <option selected="selected" value="@item.Id">@item.Title</option>
                                        }
                                        else
                                        {
                                            <option value="@item.Id">@item.Title</option>
                                        }
                                    }
                                }
                            }
                        </select>
                    </div>
                </div>
                <div class="form-cur-wall">
                    <label>作者：</label>
                    <div class="layui-input-block">
                        <input type="text" name="Author" value="@Model.Article.Author" placeholder="" maxlength="30" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="form-cur-wall">
                    <label>来源：</label>
                    <div class="layui-input-block">
                        <input type="text" name="Source" value="@Model.Article.Source" maxlength="40" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="form-cur-wall">
                    <label>更新时间</label>
                    <div class="layui-input-block">
                        <input type="text" id="EditDate" name="EditDate" value="@Model.Article.EditDate" maxlength="100" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <ul class="addpic-list clearfix">
                    <li>
                        <div class="add-photo default">
                            <input class="imgv" id="ImgUrl" name="ImgUrl" type="hidden" value="@Model.Article.ImgUrl">
                            <div class="select-newimg fyt-cloud @(!string.IsNullOrEmpty(Model.Article.ImgUrl)?"layui-hide":"")" data-text="ImgUrl" data-img="imgShow" data-type="form">
                                <i class="icon-addphote"></i>
                                <span>选择图片</span>
                            </div>
                            <div class="add-photo-wall @(!string.IsNullOrEmpty(Model.Article.ImgUrl)?"":"layui-hide")">
                                <img id="imgShow" src="@Model.Article.ImgUrl">
                                <div class="phote-edit">
                                    <a class="photo-tool fyt-cloud" data-text="ImgUrl" data-img="imgShow" data-type="form" href="javascript:void(0)"><i class="layui-icon layui-icon-edit"></i>更换</a>
                                    <a class="photo-tool last" href="javascript:void(0)" onclick="oc.deleteFile()"><i class="layui-icon layui-icon-delete"></i>删除</a>
                                </div>
                                <div class="cover">封面</div>
                            </div>
                        </div>
                    </li>
                </ul>
                <div class="form-cur-wall">
                    <label style="line-height:inherit;">内容属性：</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="Audit" @(Model.Article.Audit ? "checked=''" : "") lay-skin="primary" title="审核状态">
                        <input type="checkbox" name="IsTop" @(Model.Article.IsTop ? "checked=''" : "") lay-skin="primary" title="是否推荐">
                        <input type="checkbox" name="IsHot" @(Model.Article.IsHot ? "checked=''" : "") lay-skin="primary" title="是否热点">
                        <input type="checkbox" name="IsScroll" @(Model.Article.IsScroll ? "checked=''" : "") lay-skin="primary" title="是否滚动">
                        <input type="checkbox" name="IsSlide" @(Model.Article.IsSlide ? "checked=''" : "") lay-skin="primary" title="是否幻灯">
                        <input type="checkbox" name="IsComment" @(Model.Article.IsComment ? "checked=''" : "") lay-skin="primary" title="是否允许评论">
                        <input type="checkbox" name="IsRecyc" @(Model.Article.IsRecyc ? "checked=''" : "") lay-skin="primary" title="是否在回收站">
                    </div>
                </div>
                <div class="form-cur-wall layui-clear">
                    <label style="line-height:inherit;">发布平台：</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="like[IsWap]" @(Model.Article.IsWap ? "checked=''" : "") lay-skin="primary" title="是否手机站显示">
                    </div>
                </div>
                <div class="form-cur-wall layui-clear">
                    <label style="line-height:inherit;">权重：</label>
                    <div class="layui-input-block">
                        <div id="slideSort" style="top:8px;"></div>
                    </div>
                </div>
                <div class="text else">扩展属性</div>
                <div class="form-cur-wall">
                    <label>文章标签：</label>
                    <div class="layui-input-block">
                        <input type="text" name="Tag" value="@Model.Article.Tag" placeholder="" maxlength="100" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="form-cur-wall">
                    <label>转向连接：</label>
                    <div class="layui-input-block">
                        <input type="text" name="LinkUrl" value="@Model.Article.LinkUrl" placeholder="以http开头" maxlength="100" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="text else">点击量</div>
                <div class="form-cur-wall">
                    <label>总点击量</label>
                    <div class="layui-input-block">
                        <input type="number" name="Hits" value="@Model.Article.Hits" maxlength="50" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="form-cur-wall">
                    <label>月点击量</label>
                    <div class="layui-input-block">
                        <input type="number" name="MonthHits" value="@Model.Article.MonthHits" maxlength="50" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="form-cur-wall">
                    <label>周点击量</label>
                    <div class="layui-input-block">
                        <input type="number" name="WeedHits" value="@Model.Article.WeedHits" maxlength="50" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="form-cur-wall">
                    <label>日点击量</label>
                    <div class="layui-input-block">
                        <input type="number" name="DayHits" value="@Model.Article.DayHits" maxlength="50" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div style="height:50px;"></div>
            </div>
            <div class="layui-row">
                <div class="layui-form-item">
                    <label class="layui-form-label">文章标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="Title" value="@Model.Article.Title" maxlength="100" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">副标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="SubTitle" value="@Model.Article.SubTitle" maxlength="500" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-md6 layui-col-xs12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO关键词</label>
                        <div class="layui-input-block">
                            <textarea name="KeyWord" class="layui-textarea" style="min-height: 60px;" placeholder="SEO关键字，填写利于抓取，英文逗号分隔">@Model.Article.KeyWord</textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6 layui-col-xs12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO描述</label>
                        <div class="layui-input-block">
                            <textarea name="Summary" class="layui-textarea" style="min-height: 60px;" placeholder="SEO描述，填写利于抓取，最多200个字">@Model.Article.Summary</textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">文本域</label>
                    <div class="layui-input-block">
                        <textarea id="Content" name="Content" placeholder="请输入内容" class="layui-textarea">@Html.Raw(Model.Article.Content)</textarea>
                    </div>
                </div>
            </div>           
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
                    <a href="/fytadmin/cms/article" class="layui-btn layui-btn-primary">返回列表</a>
                </div>
            </div>
        </div>
        <input type="hidden" name="Id" id="Id" value="@Model.Article.Id" />
    </form>
    <script>
        var oc;
        layui.config({
            base: '/themes/js/modules/'
        }).use(['layer', 'jquery', 'common', 'form', 'layedit', 'laydate', 'slider'], function () {
            var form = layui.form, $ = layui.jquery, os = layui.common, laydate = layui.laydate, slider = layui.slider,sort=@Model.Article.Sort;
            var layedit = layui.layedit;
            var index = layedit.build('Content', { height:600});
            form.render();
            laydate.render({
                elem: '#EditDate'
                , theme: '#393D49'
                , type:'datetime'
            });
            $('.panel-addpic').css({ 'min-height': $(window).height() - 95 });
            var sliderIndex=slider.render({
                elem: '#slideSort'
                , input: true 
                , change: function (value) {
                    sort = value; 
                }
                , theme:'#409eff'
            });
            //赋值
            sliderIndex.setValue(@Model.Article.Sort);
           
            os.cloudFile();
            oc = {
                setContent(v) {
                    var imgIndex = v.lastIndexOf('/');
                    var str = v.substring(imgIndex + 1, v.length);
                    if (os.isExtImage(v)) {
                        layedit.setCursorText(index, '<img src="' + v + '" alt="' + str+'"/>');
                    } else {
                        layedit.setCursorText(index, '<p style="padding:12px 20px;background-color: #edf3f5;"><a href="' + v + '" target="_blank" title="' + str + '">' + str +'</a></p>');
                    }
                },
                fileSave(v) {
                    $(".select-newimg").addClass('layui-hide');
                    $(".add-photo-wall").removeClass('layui-hide');
                    $('#ImgUrl').val(v);
                    $('#imgShow').attr('src',v);
                },
                deleteFile(){
                    $(".select-newimg").removeClass('layui-hide');
                    $(".add-photo-wall").addClass('layui-hide');
                    $('#ImgUrl').val('');
                    $('#imgShow').attr('src', v);
                }
            };

            //监听提交
            form.on('submit(submit)', function (data) {
                data.field.Content = layedit.getContent(index);
                var urls = "api/article/add";
                if ($("#Id").val()!=='0') {
                    urls = "api/article/edit";
                }
                data.field.Audit = data.field.Audit === 'on' ? true : false;
                data.field.IsTop = data.field.IsTop === 'on' ? true : false;
                data.field.IsHot = data.field.IsHot === 'on' ? true : false;
                data.field.IsScroll = data.field.IsScroll === 'on' ? true : false;
                data.field.IsSlide = data.field.IsSlide === 'on' ? true : false;
                data.field.IsComment = data.field.IsComment === 'on' ? true : false;
                data.field.IsWap = data.field.IsWap === 'on' ? true : false;
                data.field.IsRecyc = data.field.IsRecyc === 'on' ? true : false;
                data.field.Sort = sort;
                os.log(data.field);
                os.ajax(urls, data.field, function (res) {
                    if (res.statusCode === 200) {
                        layer.confirm('请问您是继续添加，还是返回列表？', {
                            icon: 6,
                            btn: ['添加', '列表']
                        }, function () {
                            window.location.reload();
                        }, function () {
                            window.location.href = '/fytadmin/cms/article';
                        });

                    }
                    else {
                        os.error(res.message);
                    }
                });
                return false;
            });
        });
    </script>
</div>